package Myextends;


import bytestream.J_Echo;
import java.io.*;
public class TXTDemo
{
  public static void main(String[] args) throws Exception
  {   FileInputStream f0=null;
      FileInputStream f1=null;
      FileInputStream f2=null;
      FileInputStream f3=null;   
          
      f0=new FileInputStream("null_ansi.txt");
      f1=new FileInputStream("null_big_unicode.txt");
      f2=new FileInputStream("null_utf8.txt");
      f3=new FileInputStream("null_unicode.txt");
      
      System.out.println("ANSI格式");
      J_Echo.mb_echo(f0);      
      System.out.println("Unicode Big Endia格式");
      J_Echo.mb_echo(f1);      
      System.out.println("UTF-8格式");
      J_Echo.mb_echo(f2);
      System.out.println("Unicode格式");      
      J_Echo.mb_echo(f3);
      f0.close();f1.close();f2.close();f3.close();
      
      f0=new FileInputStream("demo_ansi.txt");
      f1=new FileInputStream("demo_big_unicode.txt");
      f2=new FileInputStream("demo_utf8.txt");
      f3=new FileInputStream("demo_unicode.txt");
      
      System.out.println("ANSI格式");
      J_Echo.mb_echo(f0);
      System.out.println("Unicode Big Endia格式");
      J_Echo.mb_echo(f1);
      System.out.println("UTF-8格式");
      J_Echo.mb_echo(f2);
      System.out.println("Unicode格式");
      J_Echo.mb_echo(f3);      
      
      f0.close();f1.close();f2.close();f3.close();

      FileReader fr0=null;
      DataInputStream fr1=null;
      InputStream fr2=null;
      
      int b;
      System.out.println("ANSI格式");
      fr0=new FileReader("demo_ansi.txt");
      while((b=fr0.read())!=-1)
      System.out.println(b+"对应可见字符  "+(char)b);
      fr0.close();

      System.out.println("Unicode Big Endia格式");
      fr1=new DataInputStream(new FileInputStream("demo_big_unicode.txt"));
      b=fr1.readByte();System.out.println(b+"对应可见字符  "+(char)b);
      b=fr1.readByte();System.out.println(b+"对应可见字符  "+(char)b);
      char c=fr1.readChar(); System.out.println((int)c+"对应可见字符  "+c);
      c=fr1.readChar(); System.out.println((int)c+"对应可见字符  "+c);
      c=fr1.readChar(); System.out.println((int)c+"对应可见字符  "+c);
      fr1.close();

      System.out.println("UTF-8格式");
      fr2=new FileInputStream("demo_utf8.txt");
      fr2.read();fr2.read();fr2.read();
      byte[] t=new byte[5];
      fr2.read(t);
      System.out.println(new String(t,"UTF8"));
      fr2.close();

      System.out.println("Unicode格式");
      fr1=new DataInputStream(new FileInputStream("demo_unicode.txt"));
      b=fr1.readByte();System.out.println(b+"对应可见字符  "+(char)b);
      b=fr1.readByte();System.out.println(b+"对应可见字符  "+(char)b);
      c=(char)(fr1.read()+(fr1.read()<<8)); 
      System.out.println((int)c+"对应可见字符  "+c);
      c=(char)(fr1.read()+(fr1.read()<<8));
      System.out.println((int)c+"对应可见字符  "+c);
      c=(char)(fr1.read()+(fr1.read()<<8));
      System.out.println((int)c+"对应可见字符  "+c);
      fr1.close();
  }
}
